package com.daxt.common.util;

import com.daxt.model.service.base.vo.Dept;
import com.sxlq.dmapi.DmpApiFactory;
import com.sxlq.dmapi.config.OrgConfig;
import com.sxlq.dmapi.config.UserConfig;
import com.sxlq.dmapi.model.Org;
import com.sxlq.dmapi.model.User;
import com.sxlq.dmapi.service.DmApiService;
import com.sxlq.dmapi.service.DmApiServiceFactory;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class SdkUtil {

    /**
     * 从SDK获取，全部的用户数据，共22766条数据
     * @return
     */
    public static List<User> getSdkUserAll(Date date){
        DmpApiFactory.start();
        DmApiService service = DmApiServiceFactory.getService(UserConfig.NAME);

        List<User> listUser=new ArrayList<>();
        if(date==null){
            int index=0;
            for (int i=0;i<300;i++){
                List<User> users= service.queryAll(index,100);
                if(users!=null){
                    //listUser.addAll(service.queryAll(index,100));
                    listUser.addAll(users);
                    index += 100;
                }
            }
        }else{
            int index=0;
            for (int i=0;i<300;i++){
                List<User> users= service.queryAllAfter(index,100,date);
                if(users!=null){
                    //listUser.addAll(service.queryAllAfter(index,100,date));
                    listUser.addAll(users);
                    index += 100;
                }
            }
        }

        return listUser;
    }

    /**
     * 从SDK获取，全部组织架构数据，共有2864条数据
     * @return
     */
    public static List<Org> getSdkDeptAll(Date date){
        DmpApiFactory.start();
        DmApiService service = DmApiServiceFactory.getService(OrgConfig.NAME);

        List<Org> listDept=new ArrayList<>();
        if(date==null){
            int index=0;
            for (int i=0;i<30;i++){
                List<Org> Orgs= service.queryAll(index,100);
                if(Orgs!=null){
                    listDept.addAll(service.queryAll(index,100));
                    index += 100;
                }
            }
        }else{
            int index=0;
            for (int i=0;i<30;i++){
                List<Org> Orgs= service.queryAllAfter(index,100, date);
                if(Orgs!=null){
                    listDept.addAll(service.queryAllAfter(index,100,date));
                    index += 100;
                }
            }
        }
        return listDept;
    }


}
